package cos.android.tim.element;

import java.util.Vector;

import cos.android.tim.utils.Point;

public class Circle implements Cloneable {

	public float getCenterX(Point origin, float height) {
		return origin.getxPos() + height / 2;
	}

	public float getCenterY(Point origin, float height) {
		return origin.getyPos() + height / 2;
	}

	public float getRadius(float height) {
		return height / 2;
	}

	public boolean colition(Point origin, Point point, float height) {

		return ((Math.sqrt(Math.pow(
				getCenterX(origin, height) - point.getxPos(), 2)
				+ Math.pow(getCenterY(origin, height) - point.getyPos(), 2))) <= getRadius(height));
	}

	public Point colition(Point origin, Element element, float height) {

		if (element.isCircle()) {
			if ((Math.sqrt(Math.pow(
					getCenterX(origin, height) - element.getCenterX(), 2)
					+ Math.pow(
							getCenterY(origin, height) - element.getCenterY(),
							2))) <= getRadius(height) + element.getRadius()) {

				return null;
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	public Vector<Point> getAristas(Point origin, float height) {
		Vector<Point> aristas = new Vector<Point>();

		double jump = (Math.PI / 4);
		float cosAux;
		float sinAux;
		double angle;
		Point arista;
		for (int i = 0; i < 8; i++) {
			angle = jump * i;
			cosAux = (float) Math.cos(angle);
			sinAux = (float) Math.sin(angle);

			arista = new Point((cosAux * getRadius(height)) + getRadius(height)
					+ origin.getxPos(), (sinAux * getRadius(height)
					+ getRadius(height) + origin.getyPos()));
			aristas.add(arista);
		}

		return aristas;

	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		return super.clone();
	}
}
